<?php
namespace app\admin\model\system;

use support\Model;
use think\model\concern\SoftDelete;

class SystemMenusModel extends Model
{
    use SoftDelete;
    protected $name = 'system_menus';

    protected $pk = 'id';

    protected $deleteTime = 'delete_time';


    /**
     * 获取权限菜单列表
     * @param array $where
     * @param array $field
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMenusRoule(array $where, ?array $field = [])
    {
        if (!$field) {
            $field = ['id', 'menu_name', 'icon', 'pid', 'sort', 'menu_path', 'is_show', 'header', 'is_header', 'is_show_path'];
        }
        return $this->where($where)->field($field)->order('sort DESC,id DESC')->failException(false)->select();
    }

    /**
     * 获取菜单中的唯一权限
     * @param array $where
     * @return array
     */
    public function getMenusUnique(array $where)
    {
        return $this->where($where)->where('unique_auth', '<>', '')->column('unique_auth', '');
    }

}